﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace TvTipper
{
    public partial class DataImportForm : Form
    {
        public DataImportForm()
        {
            InitializeComponent();
        }

        private void m_ok_Click(object sender, EventArgs e)
        {
            var updatePath = Application.StartupPath + @"\Scripts";
      
            var p = new Process();
            p.StartInfo.FileName = updatePath + @"\db_update.bat";
            p.StartInfo.WorkingDirectory = updatePath;
            p.StartInfo.UseShellExecute = true;
            try
            {
                p.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while executing update script: " + ex.Message,
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            p.WaitForExit();

            if (p.ExitCode == 1)
            {
                DialogResult = DialogResult.None;
                MessageBox.Show("Error occured during the update. Make sure the expected files are present in the path.",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("Update completed!",
                "Info",
                 MessageBoxButtons.OK,
                 MessageBoxIcon.Information);
            }
        }
    }
}
